/**
  **************************************************************************
  * @file     main.c
  * @brief    main program
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#include "at32f403a_407_board.h"
#include "at32f403a_407_clock.h"
#include "mpu_deal.h"

/** @addtogroup AT32F435_periph_examples
  * @{
  */

/** @addtogroup 435_MPU6050 I2C_MPU6050
  * @{
  */

/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
  /* initial system clock */
  system_clock_config();

  /* config nvic priority group */
  nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);

  /* at board initial */
  at32_board_init();

  /* uart initial */
  uart_print_init(115200);

  /* mpu6050 initial */
  while(mpu6050_init() != SUCCESS)
  {
    printf("mpu6050 init error\r\n");
    delay_ms(200);
  }

  /* mpu6050 calibrate */
  mpu6050_calibrate(&mpu);

  printf("mpu6050 init success\r\n");

  while(1)
  {
    if(mpu_data_read_flag == MPU_DEAL_TIME)
    {
      mpu6050_data_get(&mpu);

      mpu_data_deal(&mpu);

      mpu_data_read_flag = 0;

      printf("angle: %.1f\t%.1f\t%.1f\r\n", mpu.angle_x, mpu.angle_y, mpu.angle_z);
    }
  }
}

/**
  * @}
  */

/**
  * @}
  */
